<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="id">
              <a-input :disabled=formDisabled v-model="model.id" :max-length="36"  placeholder="请输入id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金蝶主键id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kingdeeId">
              <a-input :disabled=formDisabled v-model="model.kingdeeId" :max-length="36"  placeholder="请输入金蝶主键id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankTransNo">
              <a-input :disabled=formDisabled v-model="model.bankTransNo" :max-length="36"  placeholder="请输入银行流水号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payeeUnit">
              <a-input :disabled=formDisabled v-model="model.payeeUnit" :max-length="36"  placeholder="请输入收款公司"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="汇款日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remittanceDate">
              <j-date :disabled=formDisabled placeholder="请选择汇款日期" v-model="model.remittanceDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="汇款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remittanceAmount">
              <a-input-number :disabled=formDisabled :max="999999999" :min="0" :precision="2" v-model="model.remittanceAmount" placeholder="请输入汇款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="汇款单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remittanceUnit">
              <a-input :disabled=formDisabled v-model="model.remittanceUnit" :max-length="36"  placeholder="请输入汇款单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payeeAccountNo">
              <a-input :disabled=formDisabled v-model="model.payeeAccountNo" :max-length="36"  placeholder="请输入收款账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankName">
              <a-input :disabled=formDisabled v-model="model.bankName" :max-length="36"  placeholder="请输入收款银行"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="摘要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input :disabled=formDisabled v-model="model.remark" :max-length="36"  placeholder="请输入摘要"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payMode">
              <a-input :disabled=formDisabled v-model="model.payMode" :max-length="36"  placeholder="请输入支付方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流水类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="statementType">
              <a-input :disabled=formDisabled v-model="model.statementType" :max-length="36"  placeholder="请输入流水类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款申请状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="collectStatus">
              <a-input :disabled=formDisabled v-model="model.collectStatus" :max-length="36"  placeholder="请输入收款申请状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款单id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="financeCollectId">
              <a-input :disabled=formDisabled v-model="model.financeCollectId" :max-length="36"  placeholder="请输入收款单id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金蝶流水id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kingdeeBillId">
              <a-input :disabled=formDisabled v-model="model.kingdeeBillId" :max-length="36"  placeholder="请输入金蝶流水id"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import moment from 'moment'
  import { mapGetters } from 'vuex'

  export default {
    name: 'ErpFinanceBankStatementBillForm',
    components: {
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/add",
          edit: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/edit",
          queryById: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      ...mapGetters(['userInfo']),
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            }).catch((error)=>{
               that.$emit('unButtonDisable');
             }).finally(() => {
               that.confirmLoading = false;
             })
          }else {
           that.$emit('unButtonDisable');
          }

        })
      },
    }
  }
</script>
